<html>
<head><meta charset="utf-8"><title>Idea: Raw Keywords · edition 2021 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/index.html">edition 2021</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html">Idea: Raw Keywords</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224837211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224837211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224837211">(Feb 02 2021 at 07:38)</a>:</h4>
<p>Raw idents (r#blah) solve the problem of calling code that needs an ident that is also a keyword, and this is great for moving forward in editions without breaking things, but to help limit the amount of churn, why don't we allow raw keywords e.g. <code>k#async</code> to be equivalent to the keyword, but also usable in editions where we can't make it a keyword?</p>



<a name="224837551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224837551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224837551">(Feb 02 2021 at 07:44)</a>:</h4>
<p>what does it mean to have a keyword that hasn't been defined? It sounds like you want <code>k#async</code> to be recognized as a keyword on say rust 2015 even though it doesn't know what this keyword means, so wouldn't that always be a compile error?</p>



<a name="224837704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224837704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224837704">(Feb 02 2021 at 07:46)</a>:</h4>
<p>Using <code>k#async</code> in the Rust 2015 edition would have the same meaning as using it in the 2018 edition.</p>



<a name="224838405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224838405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224838405">(Feb 02 2021 at 07:57)</a>:</h4>
<p>If keyword meaning changes, we could also include the edition in there <code>k2024#for</code> but that situation hasn't happened yet and probably won't happen.</p>



<a name="224838500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224838500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224838500">(Feb 02 2021 at 07:59)</a>:</h4>
<p>Isn't there more to interpreting the syntax than just seeing the keyword? For example the <code>use</code> keyword didn't change in 2018 but the meaning of import statements did</p>



<a name="224838653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224838653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224838653">(Feb 02 2021 at 08:01)</a>:</h4>
<p>it's not clear to me that you can just opt in to the keyword without bringing the whole async/await semantics along with it (and those may well change between editions, or even to some extent between releases)</p>



<a name="224838908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224838908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224838908">(Feb 02 2021 at 08:04)</a>:</h4>
<p>The async/await semantics already exist; they're just unavailable syntactically in the 2015 edition. I guess with <code>use</code>, that would be a reason to do <code>k#2018use</code> if you wanted to use the 2018 semantics?</p>



<a name="224842649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224842649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224842649">(Feb 02 2021 at 08:51)</a>:</h4>
<p>This is a really interesting proposal.</p>



<a name="224842666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224842666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224842666">(Feb 02 2021 at 08:51)</a>:</h4>
<p>The language team talked, before, about the idea of having this kind of "raw keyword" mechanism.</p>



<a name="224842991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224842991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224842991">(Feb 02 2021 at 08:55)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/2919">https://github.com/rust-lang/rfcs/pull/2919</a></p>



<a name="224843048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224843048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224843048">(Feb 02 2021 at 08:56)</a>:</h4>
<p>Part of the notion was that it would work to introduce a keyword before we knew what that keyword should be, but that aspect of it ended up getting rejected.</p>



<a name="224843084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224843084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224843084">(Feb 02 2021 at 08:56)</a>:</h4>
<p>But the idea that we could allow older editions to access newer syntax in some cases, at least when the only blocker is a keyword from a newer edition, seems quite nice.</p>



<a name="224912071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224912071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224912071">(Feb 02 2021 at 18:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="296643">isHavvy</span> <a href="#narrow/stream/268952-edition/topic/Idea.3A.20Raw.20Keywords/near/224837704">said</a>:</p>
<blockquote>
<p>Using <code>k#async</code> in the Rust 2015 edition would have the same meaning as using it in the 2018 edition.</p>
</blockquote>
<p>That's a breaking change in 2015 because of macro_rules, sadly.</p>
<p>I'd definitely like to get a syntax space reserved for it in 2021, though.  (Personally I'd just make <code>{ident}#{ident}</code> and <code>{ident}@{string_lit}</code> parse as one thing always, so that we have lots of space here -- the rustfix for which would just be to put spaces around <code>#</code> in macros.)</p>



<a name="224915877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224915877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224915877">(Feb 02 2021 at 18:36)</a>:</h4>
<p>I offered <code>br#keyword</code> for this in the raw identifiers RFC, since <code>br#</code> is currently forced to be the start of a raw byte string</p>



<a name="224915888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224915888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224915888">(Feb 02 2021 at 18:36)</a>:</h4>
<p>(same reason <code>r#</code> was chosen for raw identifiers)</p>



<a name="224935870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224935870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224935870">(Feb 02 2021 at 21:01)</a>:</h4>
<p>The RFC I linked above suggested <code>r#$&lt;keyword&gt;</code>, which seems vaguely reasonable to me, and which as far as I can tell would not be a breaking change.</p>



<a name="224936047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224936047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224936047">(Feb 02 2021 at 21:02)</a>:</h4>
<p>Or am I misunderstanding why raw keywords of any kind would break macro_rules?</p>



<a name="224948888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224948888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224948888">(Feb 02 2021 at 22:50)</a>:</h4>
<p>Yeah, that one might work.  It's just even less obvious.</p>



<a name="224948918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224948918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224948918">(Feb 02 2021 at 22:51)</a>:</h4>
<p>I guess I'm less worried about allowing new keywords on editions before the introduction of a less-obtuse option.</p>



<a name="224948984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224948984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224948984">(Feb 02 2021 at 22:52)</a>:</h4>
<p>Old code wanting to keep using their old idents back into the past feels more persuasive than new keywords need to be supported on old editions -- there's no existing code.</p>



<a name="224949056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224949056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224949056">(Feb 02 2021 at 22:52)</a>:</h4>
<p>yes, it just needs to be something that does not tokenize yet. <code>r#</code> is greedy -- it used to error if that didn't start a raw string, which left room to let it take ident-start. You do get an error on <code>r#$anything</code> now, so that would be fine.</p>



<a name="224949072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224949072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224949072">(Feb 02 2021 at 22:52)</a>:</h4>
<p>So if this is only for stuff to be introduced in the future, I'd be happy to just make it <code>k#foo</code> and old have it work in 2021+</p>



<a name="224949118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/224949118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#224949118">(Feb 02 2021 at 22:53)</a>:</h4>
<p>There's also no cross-edition call patterns with keywords, like there are for idents.</p>



<a name="225201771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225201771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225201771">(Feb 04 2021 at 18:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition/topic/Idea.3A.20Raw.20Keywords/near/224935870">said</a>:</p>
<blockquote>
<p>The RFC I linked above suggested <code>r#$&lt;keyword&gt;</code>, which seems vaguely reasonable to me, and which as far as I can tell would not be a breaking change.</p>
</blockquote>
<p>I would avoid <code>$</code></p>



<a name="225201854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225201854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225201854">(Feb 04 2021 at 18:30)</a>:</h4>
<p>I am somewhat inclined to agree with <span class="user-mention" data-user-id="125270">@scottmcm</span>'s instinct of "reserve space for this in 2021 and just use it going forward"</p>



<a name="225201882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225201882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225201882">(Feb 04 2021 at 18:30)</a>:</h4>
<p>so some stuff never gets backported to 2018, so what</p>



<a name="225201990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225201990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225201990">(Feb 04 2021 at 18:31)</a>:</h4>
<p>I'm very much in favor of having uglier ways to expose "future edition" behavior in older editions</p>



<a name="225202045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225202045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225202045">(Feb 04 2021 at 18:31)</a>:</h4>
<p>The only downside I see to this particular proposal is that it isn't fully general, e.g., it wouldn't help with the pub macro rules change</p>



<a name="225202069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225202069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225202069">(Feb 04 2021 at 18:31)</a>:</h4>
<p>but that's not really an <em>objection</em> -- I guess I'm just comparing in my mind to something like <code>from __future__ import X</code></p>



<a name="225219605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225219605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225219605">(Feb 04 2021 at 20:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/268952-edition/topic/Idea.3A.20Raw.20Keywords/near/225202045">said</a>:</p>
<blockquote>
<p>The only downside I see to this particular proposal is that it isn't fully general, e.g., it wouldn't help with the pub macro rules change</p>
</blockquote>
<p>If we generalized to "give me the token from this numbered edition", it could. <code>macro_rules</code> wouldn't default to <code>pub(self)</code>, but <code>r#(some_syntax_here)2021macro_rules</code> could.</p>



<a name="225219789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225219789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225219789">(Feb 04 2021 at 20:44)</a>:</h4>
<p>It doesn't have to use <code>$</code>; we could use any sigil that isn't <code>#</code>, <code>"</code>, or a letter.</p>



<a name="225220382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225220382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225220382">(Feb 04 2021 at 20:49)</a>:</h4>
<p>As a potentially intuitive syntax, what if we did something like <code>r#2021{ xyz r#}</code> to mean "switch to 2021 edition for this span"?</p>



<a name="225220569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225220569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225220569">(Feb 04 2021 at 20:51)</a>:</h4>
<p>That's starting to sound like a <code>rust2021! { .. }</code> to switch a whole block/item to another edition.</p>



<a name="225220924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225220924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225220924">(Feb 04 2021 at 20:54)</a>:</h4>
<p>That was what I had in mind, yeah.</p>



<a name="225220991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225220991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225220991">(Feb 04 2021 at 20:54)</a>:</h4>
<p>Except that the "raw" syntax like that could theoretically work in contexts that macros don't.</p>



<a name="225221047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225221047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225221047">(Feb 04 2021 at 20:55)</a>:</h4>
<p>(That's unlikely to matter except in cases where we change the interpretation of macro syntax.)</p>



<a name="225221199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225221199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225221199">(Feb 04 2021 at 20:56)</a>:</h4>
<p>But yeah, given that it's <em>already</em> possible to embed a span from any edition in any edition (by using a macro from another crate), adding a lightweight way to do that without a separate crate seems helpful.</p>



<a name="225221250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225221250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225221250">(Feb 04 2021 at 20:56)</a>:</h4>
<p>This would also mean we wouldn't need things like <code>:pat2021</code> the next time we make such a change.</p>



<a name="225221327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225221327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225221327">(Feb 04 2021 at 20:57)</a>:</h4>
<p>And conversely, it'd allow incremental migration of syntax in a crate.</p>



<a name="225231332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225231332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225231332">(Feb 04 2021 at 22:12)</a>:</h4>
<p>Does <code>r##ident</code> parse right now? That could also be a possibility for keywords.</p>



<a name="225237878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225237878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225237878">(Feb 04 2021 at 23:07)</a>:</h4>
<p>I'm not convinced that letting people use future-edition in previous-edition is all that important.  What scenario do we see where there's a new edition <em>released</em> but it's better to hack in some <code>rust2051!</code> macros than to just migrate to the new edition, which we basically expect all actively-developed code to do anyway?</p>
<p><em>Keywords</em>, on the other hand, I can see a reason: being able to stabilize something <em>without waiting for a new edition to release</em>.  Let's say we decide in 2022 that <code>yeet e;</code> is ready to go.  It would be nice to be able to say "you can use it today as <code>k#yeet e;</code>, and in a future edition <code>yeet</code> will be a keyword so after you migrate you can remove the <code>k#</code>".</p>



<a name="225240673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225240673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225240673">(Feb 04 2021 at 23:35)</a>:</h4>
<p>I can see this enabling incremental migration of a large codebase</p>



<a name="225240813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225240813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225240813">(Feb 04 2021 at 23:37)</a>:</h4>
<p>Oh that was said already</p>



<a name="225242140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225242140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225242140">(Feb 04 2021 at 23:50)</a>:</h4>
<p>I guess I'm expecting that with <code>cargo fix</code> it's easy enough to migrate crate-by-crate.  (Maybe not to instantly fully optimally migrate, but enough that it'd still be nicer to just migrate the whole crate, check that in, then improve the code than to put <code>rust2036!</code> macros around parts.)</p>



<a name="225288105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225288105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225288105">(Feb 05 2021 at 11:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition/topic/Idea.3A.20Raw.20Keywords/near/225221199">said</a>:</p>
<blockquote>
<p>But yeah, given that it's <em>already</em> possible to embed a span from any edition in any edition (by using a macro from another crate), adding a lightweight way to do that without a separate crate seems helpful.</p>
</blockquote>
<p>Just because I was super curious about that, here is a PoC of this: behold, the <code>edition_2018!</code> macro:</p>
<p><a href="https://asciinema.org/a/L8f1xXSwRjOApLwAB5bMQvGhz">https://asciinema.org/a/L8f1xXSwRjOApLwAB5bMQvGhz</a></p>



<a name="225288552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225288552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225288552">(Feb 05 2021 at 11:45)</a>:</h4>
<p>Demo: the following code compiles on edition 2015:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">extern</span><span class="w"> </span><span class="k">crate</span><span class="w"> </span><span class="n">__future__</span><span class="p">;</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">__future__</span>::<span class="n">edition_2018</span><span class="p">;</span><span class="w"></span>

<span class="n">edition_2018</span><span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">async</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">async</span><span class="w"> </span><span class="p">{}.</span><span class="k">await</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><code>__future__</code>'s code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">//! __future/respan/src/lib.rs</span>
<span class="k">use</span><span class="w"> </span>::<span class="n">proc_macro</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>

<span class="cp">#[proc_macro]</span><span class="w"> </span><span class="k">pub</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">respan</span><span class="w"> </span><span class="p">(</span><span class="n">input</span>: <span class="nc">TokenStream</span><span class="p">)</span><span class="w"></span>
<span class="w">  </span>-&gt; <span class="nc">TokenStream</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">respan_with</span><span class="w"> </span><span class="p">(</span><span class="n">span</span>: <span class="nc">Span</span><span class="p">)</span><span class="w"></span>
<span class="w">      </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="o">'</span><span class="nb">static</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="n">TokenTree</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">TokenTree</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">move</span><span class="w"> </span><span class="o">|</span><span class="k">mut</span><span class="w"> </span><span class="n">tt</span><span class="o">|</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">tt</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="o">|</span><span class="w"> </span><span class="n">TokenTree</span>::<span class="n">Group</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">Group</span>::<span class="n">new</span><span class="p">(</span><span class="w"></span>
<span class="w">                </span><span class="n">g</span><span class="p">.</span><span class="n">delimiter</span><span class="p">(),</span><span class="w"></span>
<span class="w">                </span><span class="n">g</span><span class="p">.</span><span class="n">stream</span><span class="p">().</span><span class="n">into_iter</span><span class="p">().</span><span class="n">map</span><span class="p">(</span><span class="n">respan_with</span><span class="p">(</span><span class="n">span</span><span class="p">)).</span><span class="n">collect</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">).</span><span class="n">into</span><span class="p">(),</span><span class="w"></span>
<span class="w">            </span><span class="o">|</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">tt</span><span class="p">.</span><span class="n">set_span</span><span class="p">(</span><span class="n">tt</span><span class="p">.</span><span class="n">span</span><span class="p">().</span><span class="n">resolved_at</span><span class="p">(</span><span class="n">span</span><span class="p">));</span><span class="w"></span>
<span class="w">                </span><span class="n">tt</span><span class="w"></span>
<span class="w">            </span><span class="p">},</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">tokens</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">input</span><span class="p">.</span><span class="n">into_iter</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">span</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tokens</span><span class="p">.</span><span class="n">next</span><span class="p">().</span><span class="n">unwrap</span><span class="p">().</span><span class="n">span</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">tokens</span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="n">respan_with</span><span class="p">(</span><span class="n">span</span><span class="p">)).</span><span class="n">collect</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">//! __future__/src/lib.rs</span>

<span class="cp">#[macro_export]</span><span class="w"></span>
<span class="fm">macro_rules!</span><span class="w"> </span><span class="n">edition_2018</span><span class="w"> </span><span class="p">{(</span><span class="w"></span>
<span class="w">    </span><span class="cp">$($code</span>:<span class="nc">tt</span><span class="p">)</span><span class="o">*</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="cp">$crate</span>::<span class="n">respan</span><span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo</span><span class="w"> </span><span class="c1">// spanned here</span>
<span class="w">        </span><span class="cp">$($code</span><span class="p">)</span><span class="o">*</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">)}</span><span class="w"></span>

<span class="cp">#[doc(hidden)]</span><span class="w"> </span><span class="sd">/** Not part of the public API */</span><span class="w"> </span><span class="k">pub</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span>::<span class="n">respan</span>::<span class="n">respan</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="225530861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225530861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225530861">(Feb 08 2021 at 11:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/268952-edition/topic/Idea.3A.20Raw.20Keywords/near/225237878">said</a>:</p>
<blockquote>
<p><em>Keywords</em>, on the other hand, I can see a reason: being able to stabilize something <em>without waiting for a new edition to release</em>.  Let's say we decide in 2022 that <code>yeet e;</code> is ready to go.  It would be nice to be able to say "you can use it today as <code>k#yeet e;</code>, and in a future edition <code>yeet</code> will be a keyword so after you migrate you can remove the <code>k#</code>".</p>
</blockquote>
<p>This is the use case I have in mind</p>



<a name="225530922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225530922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225530922">(Feb 08 2021 at 11:31)</a>:</h4>
<p>I want to be able to move forward with stabilization but have the "good ergonomics" wait until next edition</p>



<a name="225530928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225530928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225530928">(Feb 08 2021 at 11:31)</a>:</h4>
<p>I also want to reduce the cost of missing the edition</p>



<a name="225530947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225530947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225530947">(Feb 08 2021 at 11:31)</a>:</h4>
<p>i.e., "this didn't quite make it into 2021, but we can expose it in 2022 this way...."</p>



<a name="225530959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225530959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225530959">(Feb 08 2021 at 11:31)</a>:</h4>
<p>plausibly we could do that with more frequent editions, but I'm interested in alternatives</p>



<a name="225545613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225545613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225545613">(Feb 08 2021 at 13:45)</a>:</h4>
<div class="codehilite"><pre><span></span><code>edition = &quot;1.52.0&quot;
</code></pre></div>



<a name="225552959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225552959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225552959">(Feb 08 2021 at 14:41)</a>:</h4>
<p>For various reasons I don't think that's the right way to go, but it's one logical conclusion</p>



<a name="225580839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Idea%3A%20Raw%20Keywords/near/225580839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Idea.3A.20Raw.20Keywords.html#225580839">(Feb 08 2021 at 17:43)</a>:</h4>
<p>yeah :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>